package tests;
import gropack.*;
import static org.junit.Assert.*;
import org.junit.Test;

public class ExprCalcTest {

	@Test
	public void testPlus() {
			ExprCalc c = new ExprCalc();
			// (1 + 2)
			Expr e = new PlusExpr(new IntExpr(1), new IntExpr(2));
			e.accept(c);
			assertTrue(c.result().equals(new IntExpr(3)));
	}

	@Test
	public void testMoins() {
			ExprCalc c = new ExprCalc();
			// (2 - 1)
			Expr e = new MoinsExpr(new IntExpr(2), new IntExpr(1));
			e.accept(c);
			assertTrue(c.result().equals(new IntExpr(1)));
	}
	
	@Test
	public void testMult() {
			ExprCalc c = new ExprCalc();
			// (2 * 2)
			Expr e = new MultExpr(new IntExpr(2), new IntExpr(2));
			e.accept(c);
			assertTrue(c.result().equals(new IntExpr(4)));
	}
	
	@Test
	public void testDiv() {
			ExprCalc c = new ExprCalc();
			// (2 / 2)
			Expr e = new DivExpr(new IntExpr(2), new IntExpr(2));
			e.accept(c);
			assertTrue(c.result().equals(new IntExpr(1)));
	}
	
	@Test
	public void testOp1() {
			ExprCalc c = new ExprCalc();
			// (2 + (4 * 2))
			Expr e = new PlusExpr(new IntExpr(2), new MultExpr(new IntExpr(4), new IntExpr(2)));
			e.accept(c);
			assertTrue(c.result().equals(new IntExpr(10)));
	}
	
	@Test
	public void testFloat() {
			ExprCalc c = new ExprCalc();
			// (2.4 + (4 * 2.0))
			Expr e = new PlusExpr(new FloatExpr(2.4f), new MultExpr(new IntExpr(4), new FloatExpr(2.0f)));
			e.accept(c);
			assertTrue(c.result().equals(new FloatExpr(10.4f)));
	}
	
	@Test
	public void testFloat2() {
			ExprCalc c = new ExprCalc();
			// (1 + (1 - 2))
			Expr e = new PlusExpr(new FloatExpr(1.0f), new MoinsExpr(new FloatExpr(1.0f), new FloatExpr(2.0f)));
			e.accept(c);
			assertTrue(c.result().equals(new FloatExpr(0.0f)));
	}
}